#!/bin/sh
cd /

egrep -q "argv=/usr/bin/maildrop|argv=/usr/bin/vacationdrop" /etc/postfix/master.cf || {
	/var/opencore/bin/masterconf set maildrop "unix - n n - - pipe flags=DRhu user=vmail argv=/usr/bin/maildrop -d \${recipient}"
}
egrep -q "smtp.*inet.*smtpd" /etc/postfix/master.cf || {
	/var/opencore/bin/masterconf set smtp "inet n - n - - smtpd"
}

if [ ! -d /etc/courier-auth ]; then
  mkdir /etc/courier-auth
fi
cd /etc
if [ -d authlib ]; then
  mv authlib/* courier-auth/
  rm -rf authlib
fi
ln -s courier-auth/ authlib
if [ -d maildrop ]; then
  mv maildrop/* courier-auth/
  rm -rf maildrop
fi
ln -s courier-auth/ maildrop

touch /etc/courier-auth/locallowercase
/var/opencore/modules/PostfixCourier.module/fixconfig

chkconfig --level 2345 postfix on
chkconfig --level 2345 courier-authlib on
chkconfig --level 2345 courier-imap on
service postfix start >/dev/null 2>&1
service courier-authlib start >/dev/null 2>&1
service courier-imap start >/dev/null 2>&1

touch /etc/openpanel/.postfixconverted
